package cn.mesmile.image.compression;

import org.springframework.util.StreamUtils;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;

/**
 * @author zb
 * @date 2021/4/6 17:22
 * @Description
 */
public class TestExec {

    public static void main(String[] args) throws IOException {
        Process process = Runtime.getRuntime().exec("C:\\Users\\Bing.Zheng1\\Desktop\\test\\test.bat");
        InputStream inputStream = process.getInputStream();

        String string = StreamUtils.copyToString(inputStream, StandardCharsets.UTF_8);
        System.out.println("string = " + string);

        System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");

        InputStream errorStream = process.getErrorStream();
        String errorStreams = StreamUtils.copyToString(errorStream, StandardCharsets.UTF_8);
        System.out.println("errorStreams = " + errorStreams);

        process.destroy();

    }
}
